package com.jiyici.model;

import org.json.JSONException;
import org.json.JSONObject;

import jiyici.Constant.ModelColumn;
import android.content.ContentValues;
import android.database.Cursor;

public class RecordParam extends ClientBaseModel {

    private static final long serialVersionUID = 7844086342475397903L;

    public long recordId;

    public long itemParamId;

    public String value;
    
    @Override
    public ContentValues toContentValues() {
        ContentValues values = super.toContentValues();
        values.put(ModelColumn.RECORD_PARAM_RECORD_ID, recordId);
        values.put(ModelColumn.RECORD_PARAM_ITEM_PARAM_ID, itemParamId);
        values.put(ModelColumn.RECORD_PARAM_VALUE, value);
        return values;
    }
    
    @Override
    public void fromCursor(Cursor c) {
        super.fromCursor(c);
        recordId = c.getLong(c.getColumnIndex(ModelColumn.RECORD_PARAM_RECORD_ID));
        itemParamId = c.getLong(c.getColumnIndex(ModelColumn.RECORD_PARAM_ITEM_PARAM_ID));
        value = c.getString(c.getColumnIndex(ModelColumn.RECORD_PARAM_VALUE));
    }
    
    @Override
    public void fromJson(JSONObject json) throws JSONException {
        super.fromJson(json);
        recordId = json.getLong(ModelColumn.RECORD_PARAM_RECORD_ID);
        itemParamId = json.getLong(ModelColumn.RECORD_PARAM_ITEM_PARAM_ID);
        value = json.getString(ModelColumn.RECORD_PARAM_VALUE);
    }
    
    @Override
    public JSONObject toJson() throws JSONException {
        JSONObject json = super.toJson();
        json.put(ModelColumn.RECORD_PARAM_RECORD_ID, recordId);
        json.put(ModelColumn.RECORD_PARAM_ITEM_PARAM_ID, itemParamId);
        json.put(ModelColumn.RECORD_PARAM_VALUE, value);
        return json;
    }

    @Override
    public String toString() {
        return "RecordParam [id=" + id + ", userId=" + userId + ", lastmodified=" + lastmodified + ", deleted="
                + deleted + ", dirty=" + dirty + ", recordId=" + recordId + ", itemParamId=" + itemParamId + ", value="
                + value + "]";
    }
}
